summaryrefslogtreecommitdiffstats
path: root/src/pages/article/[slug].tsx
diff options
context:
space:
mode:
authorArmand Philippot <git@armandphilippot.com>2022-07-22 19:00:50 +0200
committerArmand Philippot <git@armandphilippot.com>2022-07-22 19:00:50 +0200
commitde9a9eac060974a7878f2bb5577f2b135596a555 (patch)
treec443e69acabc7afca7b37b8d5d5156088da3a785 /src/pages/article/[slug].tsx
parentfe3922d039bdb5d4c063bc73543abc53a57d8464 (diff)
refactor(article): wrap useSWR with a custom hook to revalidate article
Diffstat (limited to 'src/pages/article/[slug].tsx')
-rw-r--r--src/pages/article/[slug].tsx8
1 files changed, 3 insertions, 5 deletions
diff --git a/src/pages/article/[slug].tsx b/src/pages/article/[slug].tsx
index f720fa6..572a5fc 100644
--- a/src/pages/article/[slug].tsx
+++ b/src/pages/article/[slug].tsx
@@ -25,6 +25,7 @@ import {
getSinglePageSchema,
getWebPageSchema,
} from '@utils/helpers/schema-org';
+import useArticle from '@utils/hooks/use-article';
import useBreadcrumb from '@utils/hooks/use-breadcrumb';
import useComments from '@utils/hooks/use-comments';
import usePrism, { type OptionalPrismPlugin } from '@utils/hooks/use-prism';
@@ -37,7 +38,6 @@ import Script from 'next/script';
import { ParsedUrlQuery } from 'querystring';
import { HTMLAttributes } from 'react';
import { useIntl } from 'react-intl';
-import useSWR from 'swr';
type ArticlePageProps = {
comments: Comment[];
@@ -56,9 +56,7 @@ const ArticlePage: NextPageWithLayout<ArticlePageProps> = ({
}) => {
const { isFallback } = useRouter();
const intl = useIntl();
- const { data: article } = useSWR(() => slug, getArticleBySlug, {
- fallbackData: post,
- });
+ const article = useArticle(slug, post);
const commentsData = useComments(post.id, comments);
const { items: breadcrumbItems, schema: breadcrumbSchema } = useBreadcrumb({
title: article?.title || '',
@@ -71,7 +69,7 @@ const ArticlePage: NextPageWithLayout<ArticlePageProps> = ({
if (isFallback) return <Spinner />;
- const { content, id, intro, meta, title } = article!;
+ const { content, id, intro, meta, title } = article;
const { author, commentsCount, cover, dates, seo, thematics, topics } = meta;
const headerMeta: PageLayoutProps['headerMeta'] = {